﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;

namespace ERP.DAL
{
    class Connection
    {
        private static String _connectionString;
        private static SqlConnection SqlConn = null;
        private static Connection conn = new Connection();
        private Connection()
        {
            if (String.IsNullOrEmpty(_connectionString) == false)
                SqlConn = new SqlConnection(_connectionString);
        }

        public static SqlConnection GetConnection()
        {
            return SqlConn;
        }

        public static String ConnectionString
        {
            get { return _connectionString; }
            set 
            {
                if (_connectionString != value)
                {

                    if (SqlConn != null)
                    {
                        try
                        {
                            SqlConn.Close();
                        }
                        catch (Exception e)
                        {
                        }
                    }

                    _connectionString = value;
                    SqlConn = new SqlConnection(_connectionString);
                }
            }
        }

    }
}
